function sleep(delay) {
  var start = (new Date()).getTime();
  while ((new Date()).getTime() - start < delay) {
    continue;
  }
}

const pageMap = {}

function Page(obj) {
    pageMap[obj.name] = obj
    obj.setData = function(data) {
        obj.data = Object.assign(obj.data, data)
        console.log('fresh', obj.data)
        sleep(300);
    }
}

const wx = {
    gotoPage: function(name) {
        obj = pageMap[name]
        obj.onLoad ? obj.onLoad() : null
        obj.onReady ? obj.onReady() : null

        setTimeout(function() {
            obj.doAction ? obj.doAction({
                eventName: 'tap',
            }) : null
        }, 3000)
    }
}

module.exports = {
    Page,
    wx,
}
